package com.yusong.test.listener;

/**
 * Created by yusong on 2017/3/7.
 */
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.List;
public class EmailBean implements ApplicationContextAware {
    private List<String>       blackList;
    private ApplicationContext ctx;
    public void setBlackList(List<String> blackList) {
        this.blackList = blackList;
    }
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.ctx = applicationContext;
    }
    public void sendEmail(String address) {
        if (blackList.contains(address)) {
            BlackListEvent event = new BlackListEvent(address);
            //通过context发布，ApplicationContext继承了ApplicationPublisher
            ctx.publishEvent(event);
            return;
        }
    }
}